package com.starsea.book.base

import androidx.lifecycle.ViewModel
import androidx.viewbinding.ViewBinding
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.BasePopupView
import com.starsea.book.constant.Theme

abstract class VMBaseActivity<VB : ViewBinding, VM : ViewModel>(
    fullScreen: Boolean = true,
    theme: Theme = Theme.Auto,
    toolBarTheme: Theme = Theme.Auto,
    transparent: Boolean = false,
    imageBg: Boolean = true
) : BaseActivity<VB>(fullScreen, theme, toolBarTheme, transparent, imageBg) {

    protected abstract val viewModel: VM

    var show: BasePopupView? = null

    open fun showLoading(
        message: String = "请求网络中...",
        dismissOnBack: Boolean = true,
        dismissOnTouchOut: Boolean = false
    ) {
        show = XPopup.Builder(this)
            .isDestroyOnDismiss(true)
            .dismissOnBackPressed(dismissOnBack)
            .dismissOnTouchOutside(dismissOnTouchOut)
            .asLoading(message)
        show!!.show()
    }

    open fun dismissLoading() {
        show?.dismiss()
    }
}